import { FormSchema } from '/@/components/Form';

export const formSchema: FormSchema[] = [
  // {
  //   field: 'passwordOld',
  //   label: '当前密码',
  //   component: 'InputPassword',
  //   required: true,
  // },
  {
    field: 'passwordNew',
    label: '新密码',
    component: 'StrengthMeter',
    componentProps: {
      placeholder: '新密码'
    },
    dynamicRules: () => {
      return [
        {
          required: true,
          validator: (_, value: string) => {
            if (!value || value.length < 7) {
              return Promise.reject('密码长度不能小于8位')
            }
            const regexp = new RegExp(/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])/)
            if (!regexp.test(value)) {
              return Promise.reject('密码中应同时包含数字、大写字母、小写字母')
            }
            // const regexp = new RegExp(/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@!#$%^&*+-.])[\da-zA-Z@!#$%^&*+-.]/)
            // if (!regexp.test(value)) {
            //   return Promise.reject('密码中应同时包含数字、大写字母、小写字母及特殊字符')
            // }
            return Promise.resolve()
          }
        }
      ]
    }
  },
  {
    field: 'confirmPassword',
    label: '确认密码',
    component: 'InputPassword',

    dynamicRules: ({ values }) => {
      return [
        {
          required: true,
          validator: (_, value) => {
            if (!value) {
              return Promise.reject('密码不能为空');
            }
            if (value !== values.passwordNew) {
              return Promise.reject('两次输入的密码不一致!');
            }
            return Promise.resolve();
          },
        },
      ];
    },
  },
];
